// pages/brand/brand.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		foodList: '',
		http: getApp().globalData.map,
		curId:'',
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		let that=this
		wx.request({
			url: getApp().globalData.http + 'action=getClassList',
			success: (e) => {
				console.log(e)
				let foodList=e.data.data
				for(let i in e.data.data){
					foodList[i].CLASS_ID=String('a'+e.data.data[i].CLASS_ID)
				}
				console.log(foodList)
				this.setData({
					foodList:foodList,
					curId:e.data.data[0].CLASS_ID
				})
			}
		})
		wx.getSystemInfo({
			success: function(res) {
				that.setData({
					height: res.windowHeight
				});
			}
		})
	},

	clickMenu: function(e) {
		let tat = e.currentTarget.dataset.id
		console.log(tat)
		this.setData({
			curId: tat,
			toView: tat
		})
	},
	scroll: function(e) {
		var scrollTop = e.detail.scrollTop, //滚动的Y轴
			h = 0,
			seletedId;
		this.data.foodList.forEach(function(item, i) {
			var _h = 30 +Math.ceil(item.childs.length/3)  * 80; //获取右侧内容每个部分的高度
			if (scrollTop >= h) {
				seletedId = item.CLASS_ID;
			}
			h += _h;
		});
		this.setData({
			curId: seletedId
		});
	},
	nav(e){
		let pages = getCurrentPages(); // 当前页的数据，可以输出来看看有什么东西
		let prevPage = pages[pages.length - 2];
		console.log(prevPage.route)
		if(prevPage.route=='pages/index/index'){
			wx.navigateTo({
				url:'../list/list?state=0&xx=&brand='+e.currentTarget.dataset.id
			})
		}else{
			prevPage.setData({
				brand: e.currentTarget.dataset.id,
				addText:e.currentTarget.dataset.text
			})
			wx.navigateBack({
				delta: 1
			})
		}
	}
})
